<template>
  <div class="footer-feedback" v-if="feedbackMessage">
    <div class="feedback-content" :class="feedbackType">
      <div class="feedback-icon">
        {{ feedbackType === 'success' ? '✅' : '❌' }}
      </div>
      <div class="feedback-text">{{ feedbackMessage }}</div>
      <button @click="closeFeedback" class="close-btn">✕</button>
    </div>
    <div class="copyright">
      © 2025 Elasticsearch SQL Client - 让Elasticsearch查询更简单
    </div>
  </div>
  <div class="footer-feedback" v-else>
    <div class="copyright">
      © 2025 Elasticsearch SQL Client - 让Elasticsearch查询更简单
    </div>
  </div>
</template>

<script>
export default {
  name: 'FooterFeedback',
  props: {
    feedbackMessage: {
      type: String,
      default: ''
    },
    feedbackType: {
      type: String,
      default: 'success' // 'success' or 'error'
    }
  },
  data() {
    return {
      autoCloseTimer: null
    };
  },
  watch: {
    feedbackMessage: {
      handler(newMessage) {
        // 清除之前的定时器
        if (this.autoCloseTimer) {
          clearTimeout(this.autoCloseTimer);
        }
        
        // 如果有新消息且不是空字符串，设置3秒后自动关闭
        if (newMessage) {
          this.autoCloseTimer = setTimeout(() => {
            this.closeFeedback();
          }, 3000);
        }
      },
      immediate: true
    }
  },
  methods: {
    closeFeedback() {
      // 清除定时器
      if (this.autoCloseTimer) {
        clearTimeout(this.autoCloseTimer);
        this.autoCloseTimer = null;
      }
      this.$emit('close-feedback');
    }
  },
  beforeUnmount() {
    // 组件销毁前清除定时器
    if (this.autoCloseTimer) {
      clearTimeout(this.autoCloseTimer);
    }
  }
}
</script>

<style scoped>
.footer-feedback {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.feedback-content {
  display: flex;
  align-items: center;
  justify-content: center; /* 文字居中显示 */
  padding: 12px 20px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  min-height: 48px;
}

.feedback-content.success {
  background-color: #F0FFF4;
  color: #22543D;
  border-top: 1px solid #C6F6D5;
}

.feedback-content.error {
  background-color: #FFF5F5;
  color: #742A2A;
  border-top: 1px solid #FED7D7;
}

.feedback-icon {
  margin-right: 12px;
  font-size: 16px;
}

.feedback-text {
  flex: 1;
  text-align: center; /* 文字居中 */
}

.close-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: inherit;
  padding: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.close-btn:hover {
  background-color: rgba(0, 0, 0, 0.1);
}

.copyright {
  text-align: center;
  padding: 12px 20px;
  background-color: white;
  color: #718096;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  border-top: 1px solid #E2E8F0;
}
</style>